package cn.enilu.flash.api.controller.house;

import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.entity.house.RepairInfo;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.enums.body.FeeState;
import cn.enilu.flash.enums.body.RepairState;
import cn.enilu.flash.service.house.RepairInfoService;
import cn.enilu.flash.utils.BeanUtil;
import cn.enilu.flash.utils.StringUtils;
import cn.enilu.flash.utils.factory.Page;
import cn.enilu.flash.warpper.RepairInfoarpper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/repair")
public class RepairInfoController {
	@Autowired
	private RepairInfoService repairInfoService;

	@RequestMapping(value = "/list",method = RequestMethod.GET)
	public Object list(@RequestParam(required = false) String code,
					   @RequestParam(required = false) String applyMobile,
					   @RequestParam(required = false) String state,
					   @RequestParam(required = false) String feeState) {
		Page<RepairInfo> page = new PageFactory<RepairInfo>().defaultPage();
		page.addFilter("code", SearchFilter.Operator.EQ, code);
		page.addFilter("applyMobile", SearchFilter.Operator.EQ, applyMobile);
		if(StringUtils.isInteger(state) && !StringUtils.equals("--", RepairState.valueOfCode(Integer.parseInt(state))) ){
			page.addFilter("state", SearchFilter.Operator.EQ, state);
		}
		if(StringUtils.isInteger(feeState) && !StringUtils.equals("--", FeeState.valueOfCode(Integer.parseInt(feeState))) ){
			page.addFilter("feeState", SearchFilter.Operator.EQ, feeState);
		}
		page = repairInfoService.queryPage(page);
		List list = (List) new RepairInfoarpper(BeanUtil.objectsToMaps(page.getRecords())).warp();
		page.setRecords(list);
		return Rets.success(page);
	}

}